import {BasicColumn, FormSchema} from '/@/components/Table';
import {
  getAccountNameList,
  getAdminUserNameList,
  getNormalUserNameList
} from "/@/api/system/system";
import {h} from "vue";
import {Tag} from "ant-design-vue";
import {getTaskTypeList} from "/@/api/taskCenter/taskType";

export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 50,
    align: 'center',
  },
  {
    title: '任务标题',
    dataIndex: 'title',
    width: 250,
    align: 'center',
  },
  {
    title: '任务类型',
    dataIndex: 'task_type_name',
    width: 120,
    align: 'center',
    customRender: ({record}) => {
      const name = record.task_type_name || '无'
      return h(Tag, {color: 'blue'}, () => name);
    },
  },
  {
    title: '任务性质',
    dataIndex: 'is_temporary',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const status = record.is_temporary;
      const color = status === 1 ? 'gray' : 'blue';
      const text = status === 1 ? '临时任务' : '长期任务';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '审批类型',
    dataIndex: 'need_report',
    width: 120,
    align: 'center',
    customRender: ({record}) => {
      const name = record.need_report === 0 ? '无需审批' : '需要审批'
      const color = record.need_report === 0 ? 'orange' : 'blue'
      return h(Tag, {color: color}, () => name);
    },
  },
  {
    title: '奖励内容',
    dataIndex: 'reward',
    width: 200,
    align: 'center',
  },
  {
    title: '奖励单位',
    dataIndex: 'reward_unit',
    width: 100,
    align: 'center',
  },
  {
    title: '审核员',
    dataIndex: 'auditor_name',
    width: 100,
    align: 'center',
  },
  {
    title: '超级审核员',
    dataIndex: 'super_auditor_name',
    width: 100,
    align: 'center',
  },
  // {
  //   title: '任务修改时间',
  //   dataIndex: 'update_time',
  //   width: 180,
  //   align: 'center',
  // },
  {
    title: '任务状态',
    dataIndex: 'status',
    width: 100,
    align: 'center',
    customRender: ({record}) => {
      const status = record.status;
      const color = status === 0 ? 'green' : 'red';
      const text = status === 0 ? '开启' : '关闭';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '是否在小程序首页显示',
    dataIndex: 'show_in_list',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const status = record.show_in_list;
      const color = status === 1 ? 'green' : 'gray';
      const text = status === 1 ? '显示' : '隐藏';
      return h(Tag, {color: color}, () => text);
    },
  },

];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '任务ID',
    component: 'Input',
    colProps: {span: 8},
  },
  {
    field: 'title',
    label: '任务标题',
    component: 'Input',
    colProps: {span: 8},
  },
  {
    field: 'task_type',
    label: '任务类型',
    component: 'ApiSelect',
    componentProps: {
      api: getTaskTypeList,
      params: {},
      labelField: 'name',
      valueField: 'id',
    },
    colProps: {span: 8},
  },
  {
    field: 'auditor_id',
    label: '审核员',
    component: 'ApiSelect',
    componentProps: {
      api: getAccountNameList,
      params: {},
      labelField: 'real_name',
      valueField: 'user_id',
    },
    colProps: {span: 8},
  },
  {
    field: 'status',
    label: '任务状态',
    component: 'Select',
    defaultValue: 0,
    componentProps: {
      options: [
        {label: '开启', value: 0},
        {label: '关闭', value: 1},
      ],
    },
    colProps: {span: 8},
  },
];

//新增弹窗form字段
export const formSchema: FormSchema[] = [
  {
    label: 'ID',
    field: 'id',
    component: 'Input',
    defaultValue: 0,
    show: false,
  },
  {
    label: '任务类型',
    field: 'task_type',
    component: 'ApiSelect',
    componentProps: {
      api: getTaskTypeList,
      params: {item: 'taskType'},
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    field: 'title',
    label: '任务标题',
    component: 'Input',
    required: true,
  },
  {
    field: 'reward',
    label: '奖励数量',
    component: 'Input',
    required: true,
  },
  {
    field: 'reward_tips',
    label: '说明',
    component: 'InputTextArea',
    componentProps:{
      disabled:true,
      placeholder:'奖励数量字段填写说明：无需审批的临时任务，这里需要填写数字。追加任务后立刻给老师增加对应分值。'
    },
    required: false,
  },
  {
    label: '奖励单位',
    field: 'reward_unit',
    component: 'Input',
    required: false,
  },
  {
    label: '审核员',
    field: 'auditor_id',
    component: 'ApiSelect',
    componentProps: {
      api: getNormalUserNameList,
      params: {},
      labelField: 'real_name',
      valueField: 'user_id',
    },
    required: true,
  },
  {
    label: '二次审核员',
    field: 'super_auditor_id',
    component: 'ApiSelect',
    componentProps: {
      api: getAdminUserNameList,
      params: {},
      labelField: 'real_name',
      valueField: 'user_id',
    },
    required: true,
  },
  {
    field: 'status',
    label: '是否开启任务',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        {label: '开启', value: 0},
        {label: '关闭', value: 1},
      ],
    },
    required: true,
  },
  {
    field: 'need_report',
    label: '是否需要审批',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        {label: '是', value: 1},
        {label: '否', value: 0},
      ],
    },
    required: true,
  },
  {
    field: 'show_in_list',
    label: '在小程序首页显示',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        {label: '显示', value: 1},
        {label: '隐藏', value: 0},
      ],
    },
    required: true,
  },
  {
    field: 'show_in_list_tips',
    label: '说明',
    component: 'InputTextArea',
    componentProps:{
      disabled:true,
      placeholder:'[在小程序首页显示]说明：只对长期任务有效，临时任务默认在小程序隐藏。'
    },
    required: false,
  },
  {
    field: 'is_temporary',
    label: '任务性质',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        {label: '长期任务', value: 0},
        {label: '临时任务', value: 1},
      ],
    },
    required: true,
  },
];
